package com.ninong.ker.gateway.conf;

import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 启动时候将白名单url set到redis中
 * @author jmz
 */
@Component
public class AllowRunner implements CommandLineRunner {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private FilterProperties filterProperties;

    @Override
    public void run(String... args) throws Exception {
        List<String> allowPaths = filterProperties.getAllowPaths();
        redisTemplate.delete("allowPaths");
        redisTemplate.opsForList().leftPushAll("allowPaths",allowPaths);
    }
}
